package a07_二叉树;

/**
 * <p>
 * a22_验证二叉搜索树复习4
 * </p>
 *
 * @author flyduck
 * @since 2025/4/16
 */
public class a23_验证二叉搜索树复习4 {

    private TreeNode prevNode = null;

    //左中右
    public boolean isValidBST(TreeNode root) {

        if (root == null) {
            return true;
        }

        boolean leftIsValidBST = isValidBST(root.left);

        if(prevNode != null && root.val <= prevNode.val){
            return false;
        }
        prevNode = root;

        boolean rightIsValidBST = isValidBST(root.right);

        return leftIsValidBST && rightIsValidBST;
    }
}
